package com.eleventwelve.iris.web.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.opentides.util.StringUtil;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import com.eleventwelve.iris.entity.MedicalProgramTreatment;
import com.eleventwelve.iris.entity.PatientMedicalProgram;
import com.eleventwelve.iris.service.MedicalProgramTreatmentService;

public class DeleteMedicalProgramTreatmentController extends AbstractController{
	private MedicalProgramTreatmentService medicalProgramTreatmentService;
	
	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		PatientMedicalProgram program = null;
		
		String id = request.getParameter("id");
		if(!StringUtil.isEmpty(id) && StringUtils.isNumeric(id)){
			MedicalProgramTreatment programTreatment = medicalProgramTreatmentService.load(id);
			program = programTreatment.getPatientMedicalProgram();
			medicalProgramTreatmentService.delete(id);
		}
		
		return new ModelAndView("redirect:/patient-program.jspx?id="+program.getId()+"&action=delete");
	}

	public MedicalProgramTreatmentService getMedicalProgramTreatmentService() {
		return medicalProgramTreatmentService;
	}

	public void setMedicalProgramTreatmentService(
			MedicalProgramTreatmentService medicalProgramTreatmentService) {
		this.medicalProgramTreatmentService = medicalProgramTreatmentService;
	}

}
